<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            padding: 100px;
        }

        .con-inp {
            position: relative;
            width: 200px;
            height: 30px;
        }

        #inp {
            box-sizing: border-box;
            width: 100%;
            height: 100%;
            border: none;
            border-bottom: 1px solid black;
            outline: none;

        }

        .bar {
            position: absolute;
            bottom: 0px;
            width: 0;
            height: 2px;
            background-color: rgb(64, 147, 214);
            transition: all 0.3s ease-in-out;
        }

        .span-username {
            position: absolute;
            top: 0;
            left: 0;
            color: #aaa;
            transition: transform 0.3s ease-in-out;
        }

        #inp:valid~.span-username,
        #inp:focus~.span-username {
            transform: translateY(-30px);
            color: rgb(64, 147, 214);
            font-size: 18px;
        }

        #inp:focus~.bar {
            width: 100%;
        }
    </style>
</head>

<body>
    <div class="con-inp">
        <input type="text" required id="inp">
        <div class="bar"></div>
        <label for="inp" class="span-username">userName</label>
    </div>
</body>

</html>